/**
*      author: Y_Yao
*      created: 2025-02-01 20:21:59
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 7;
int n,q;
int a[N];
int b[N];

void solve()
{
    cin >> n >> q;
    int cnt = 0;
    for(int i = 1;i <= n;i++)
    {
        a[i] = 1;
        b[i] = i;
    }
    while(q--)
    {
        int o;
        cin >> o;
        if(o == 1)
        {
            int p,h;
            cin >> p >> h;
            a[b[p]]--;
            if(a[b[p]] == 1) cnt--;
            a[h]++;
            if(a[h] == 2) cnt++;
            b[p] = h;
        }
        else
        {
            cout << cnt << endl;
        }
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}